<%@ page import="com.zufangbao.gluon.api.quark.Constant"%>
<%@ page import="com.zufangbao.gluon.api.quark.ParticalStatus" %>
<%@ page import="com.zufangbao.gluon.api.quark.ParticalType" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

 <c:set var="particalTypeList" value="<%=ParticalType.values() %>"></c:set>
 <c:set var="particalStatusList" value="<%=ParticalStatus.values() %>"></c:set>
  <fmt:setBundle basename="ApplicationMessage" />
  <fmt:setLocale value="zh_CN" />

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  <link href="${ctx.resource}/css/select2.css" rel="stylesheet">
  <link href="${ctx.resource}/css/select2-bootstrap.css" rel="stylesheet">
  <title>详情 - 支付应用 - 租房宝金融管理平台</title>
  
</head>
<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>

  <div class="web-g-main">

	<%@ include file="/WEB-INF/include/aside.jsp"%>

    <div class="content">

      <div class="panel-body">

        <div class="col-xs-12 earth-panel-layout-right">
          
          <div class="row">
            <div class="col-xs-12">
            
              <div class="panel panel-default feature-panel partical" particalId = "${partical.id }" particalUniqueId="${partical.uniqueParticalId }">
              
                <div class="panel-heading">
                  <h3 class="panel-title">应用实体</h3>
                </div>
                
                <div class="panel-body">
                
	                  <div class="row">
	                  
	                    <label class="col-xs-2 control-label">名称</label>
	                    <div class="col-xs-4">
	                      <input type="text" class="form-control" name="particalName" value="${partical.particalName }" data-validate="required">
	                    </div>
	                    
	                    <label class="col-xs-2 control-label">地址</label>
	                    <div class="col-xs-4">
	                      <input type="text" class="form-control" name="entryUrl" value="${partical.entryUrl }" data-validate="required">
	                    </div>
                    
                  </div>
                  <br/>
                   <div class="row">
                  
	                    <label class="col-xs-2 control-label">类型</label>
	                    <div class="col-xs-4">
	                      		<select class="form-control" name="particalType">
			                      	<c:forEach var="particalType" items="${particalTypeList}">
			                      	
		                      				<option value="${particalType.name }" <c:if test="${particalType.name eq partical.particalType.name }">selected</c:if>>
		                      					<fmt:message key="${particalType.key }"/>
		                      				</option>
		                      		
			                      	</c:forEach>
		                      	</select>
	                    </div>
	                    
	                    <label class="col-xs-2 control-label">状态</label>
	                    <div class="col-xs-4">
	                     		<select class= "form-control" name="particalStatus">
			                      	<c:forEach var="particalStatus" items="${particalStatusList}">
			                      	
		                      				<option value="${particalStatus.name }" <c:if test="${particalStatus.name eq partical.particalStatus.name }">selected</c:if>>
		                      					<fmt:message key="${particalStatus.key }"/>
		                      				</option>
		                      		
			                      	</c:forEach>
		                      	</select>
	                    </div>
                    
                  </div>
                  <br/>
                  <div class="row">
                  	<div class="col-xs-1 col-xs-offset-11">
                  		<button class="btn btn-primary partical-save">保存</button>
                  	</div>
                  </div>
                  
              </div>
            </div>
          </div>
          
          <div class="row">
          	<div class="col-xs-12">
            
              <div class="panel panel-default feature-panel">
              	<div class="panel-heading">
                  <h3 class="panel-title">应用参数</h3>
                </div>
                  <div class="panel-body">
					<div class="col-xs-12">
						<table
							class="table table-striped demo2do-table bottom-margin-20">
							<thead>
								<tr>
									<th>选择</th>
									<th>名称</th>
									<th>值</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="particalModel"
									items="${particalModels}">
									<tr partical-model-id="${particalModel.id }">
										<td><input type="checkbox" class ="partical-model-checkbox"></td>
										<td>${particalModel.name}</td>
										<td>${particalModel.value}</td>
										<td><a href="javascript:void(0)" class="partical-model-edit">编辑</a></td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="row">
							<div class="col-xs-1">
								<button class="btn btn-default partical-model-select">全选/反选</button>
							</div>
							<div class="col-xs-1 col-xs-offset-9">
								<button class="btn btn-primary partical-model-add">新增</button>
							</div>
							<div class="col-xs-1">
								<button class="btn btn-primary partical-model-delete">删除</button>
							</div>
						</div>
					</div>
					</div>
			    </div>
			  </div>	
            </div>

		</div><!-- layout right -->

      </div><!-- panel body -->
      
    </div><!-- panel layout -->
	</div>
  </div><!-- main content -->
  
   <!-- partical model  begin -->
  <div class="modal fade in" id="partical-model" role="dialog" tabindex="-1" aria-labelledby="dialoglabel" aria-hidden="true" partical-uniqueid="${partical.uniqueParticalId }">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="dialoglabel">配置</h4>
			</div>
			<div class="modal-body">
				<div class="row"> 
					<div class="col-xs-6">
						<input type="text" class="form-control" name="partical-model-name" placeholder="配置项名称"/>
					</div>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="partical-model-value" placeholder="配置项值"/>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default close-dialog" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary partical-model-save" data-dismiss="modal">保存</button>
			</div>
		</div>
	</div>
  </div><!-- partical model end -->
  
    <!-- dialog begin -->
  <div class="modal fade in bs-example-modal-sm" id="dialog" role="dialog" tabindex="-1" aria-labelledby="dialoglabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close close-dialog" aria-label="关闭" ><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="dialoglabel">提示</h4>
			</div>
			<div class="modal-body">
				<p></p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default close-dialog">关闭</button>
			</div>
		</div>
	</div>
  </div><!-- dialog end -->

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <script src="${ctx.resource}/js/bootstrap-alert-fade-trigger.js"></script>
  <script src="${ctx.resource}/js/circles.min.js"></script>
  <script src="${ctx.resource}/js/bootstrap-switch.min.js"></script>
  <script src="${ctx.resource}/js/bootstrap-modal-trigger.js"></script>
  <script src="${ctx.resource}/js/select2.min.js"></script>
  <script src="${ctx.resource}/js/select2_locale_zh-CN.js"></script>
  <script src="${ctx.resource}/js/earth-preupload.js"></script>
  <script src="${ctx.resource }/js/jquery.form.min.js"></script>
  <script>
 	 $(function(){
 		 
 		$(".partical-save").click(function(){
 			
 			$.post('${ctx}/particalsystem/partical-update',
 					{
 						id:$('.partical').attr("particalId").trim(),
 						particalName:$("input[name='particalName']").val().trim(),
 						entryUrl:$("input[name='entryUrl']").val().trim(),
 						particalType:$("select[name='particalType']").val().trim(),
 						particalStatus:$("select[name='particalStatus']").val().trim(),
 						originParticalId:$('.partical').attr("particalUniqueId").trim()
 						
 					}).done(function(data){
 				
 				var jsonData = $.parseJSON(data);
 				
 				resultHandler(jsonData.message,false);
 				
 				var href = window.location.href;
 				
 				var index = href.indexOf("particalUniqueId=");
 				
 				var location = "";
 				
 				if(index > - 1){
 					
	 				location = href.replace(/particalUniqueId=\w*/,"particalUniqueId="+jsonData.data.particalUniqueId);
 				}else{
 					location = href + "?particalUniqueId="+jsonData.data.particalUniqueId;
 				}
 				
 				
 				setTimeout(function(){
 					window.location=location;},1000);
 				
 		});
 	});
  		
 		var selectCount = 0;
 		
  		$(".partical-model-select").click(function(){
  			
  			if(selectCount % 2 == 0){
  				
  				$(".partical-model-checkbox").attr("checked","checked");
  			}else{
  				
  				$(".partical-model-checkbox").removeAttr("checked");
  			}
  			selectCount++;
  			
  			if(selectCount % 2 == 0){
  				
  				window.location.reload();
  			}
  		}); 
  		
  		 $(".partical-model-add").click(function(){
  			 
  			 $("#partical-model").modal();
  			 
  		 });
  		 $(".partical-model-edit").click(function(){
  			
  			var $tr = $(this).parents("tr");
  			
  			$("#partical-model").attr("partical-model-id",$tr.attr("partical-model-id"));
  			
  			$("#partical-model input[name='partical-model-name']").val($tr.children('td').eq(1).text());
  			
  			$("#partical-model input[name='partical-model-value']").val($tr.children('td').eq(2).text());
  			
  			$("#partical-model").modal();
  		 });
  		 
  		 $(".partical-model-save").click(function(){
  			 
  			 var particalUniqueId = $("#partical-model").attr("partical-uniqueid");
  			 
  			 var isNew = $("#partical-model").attr("partical-model-id") == undefined;
  			 
  			 var particalModelName = $("input[name='partical-model-name']").val().trim();
  			 
  			 var pariticalModelValue = $("input[name='partical-model-value']").val().trim();
  			 
  			 if(particalUniqueId == undefined || particalUniqueId == ''){
  				 
  				resultHandler("请先保存应用实体！",false);
 				 
  				return false;
  				 
  			 }
  			 
  			 if(particalModelName == '' || pariticalModelValue == ''){
  				 
  				resultHandler("配置项的名称或值不能为空！",false);
  				 
  				return false;
  			 }
  			 
  			 var saveParticalModelUrl = '${ctx}/particalsystem/update-partical-modles';
  			 
  			var particalModel = new Object();
				 
			 particalModel.name = particalModelName;
			
			 particalModel.value = pariticalModelValue;
			
			 particalModel.uniqueParticalId = particalUniqueId;
			 
			 if(!isNew){
				 
				 particalModel.id = $("#partical-model").attr("partical-model-id");
			 }
			 
			 var praticalModels  = [];
  				 
			praticalModels.push(particalModel);
			 
			 $.post(saveParticalModelUrl,{
				 
				particalModels:JSON.stringify(praticalModels)
				 
			 }).done(function(data){
				 
				 var message = $.parseJSON(data).message;
  				 
  				 resultHandler(message,true);
				 
			 });
  			 
  		 });
  		 
  		 $(".partical-model-delete").click(function(){
  			 
  			 var checkedParticalModels = $(".partical-model-checkbox:checked");
  			 
  			 var isSelected = checkedParticalModels.length > 0;
  			 
  			 if(! isSelected){
  				 
  				 resultHandler("请勾选要删除项！",false);
  				 
  			 }
  			 var particalModelIds = [];
  			 
  			 checkedParticalModels.each(function(){
  				 
  				particalModelIds.push($(this).parents("tr").attr("partical-model-id"));
  			 });
  			 $.post('${ctx}/particalsystem/delete-partical-models',{
  				 
  				particalModelIds:JSON.stringify(particalModelIds)
  				
  			 }).done(function(data){
  				 
  				 var message = $.parseJSON(data).message;
  				 
  				 resultHandler(message,true);
  				 
  			 })
  			 
  		 });
  		 var resultHandler = function(message,isReload){
  			 
			 $('#dialog').find('p').text(message).end().modal();
			 
			 $('#dialog .close-dialog').click(function(){
				 
				 $('#dialog').modal('hide');
				 
				 if(isReload){
				 
					 window.location.reload();
				};
			
			 });
  		 };
  	});
  </script>
  
</body>
</html>
